import { View } from "@tarojs/components";
import {
  Image,
  Button,
  Tabs,
  Loading,
  Empty,
  Toast,
  Dialog,
  Navbar,
  List,
  Field,
  Input,
} from "@taroify/core";
import { ArrowDown } from "@taroify/icons";
import BannerIcon from "@/assets/images/banner.png";
import { useEffect, useRef, useState } from "react";
import ShenheIcon from "@/assets/images/shenhe.png";
import DjiesuanIcon from "@/assets/images/djiesuan.png";
import YjiesuanIcon from "@/assets/images/yjiesuan.png";
import TixianIcon from "@/assets/images/tixian.png";
import NoIcon from "@/assets/images/no.png";
import FuzhiIcon from "@/assets/images/fuzhi.png";
import A1Icon from "@/assets/images/a1.png";
import A2Icon from "@/assets/images/a2.png";
import A3Icon from "@/assets/images/a3.png";
import { abortRequest, requestGET, requestPOST } from "@/request";
import Taro from "@tarojs/taro";
import { useSelector } from "react-redux";
import { RootState } from "@/store";
import useSyncCallback from "@/hooks/useSyncCallback";

export default function Revenue() {
  const baseURL = process.env.TARO_APP_API;

  const merchantType = useSelector(
    (state: RootState) => state.userInfo.merchantType
  );

  const merchantInfo = useSelector(
    (state: RootState) => state.userInfo.merchantInfo
  );

  const [active, setActive] = useState(0);
  const [value, setValue] = useState<any>("");
  const [more, setMore] = useState(false);

  const [value1, setValue1] = useState("");
  const [more1, setMore1] = useState(false);

  const [value2, setValue2] = useState(1);
  const [value3, setValue3] = useState("");
  const [more2, setMore2] = useState(false);

  const [profitList, setProfitList] = useState<any>([]);
  const [loading, setLoading] = useState(false);

  const [orderList, setOrderList] = useState<any[]>([]);
  const [loading1, setLoading1] = useState(false);

  const [goodsList, setGoodsList] = useState<any[]>([]);
  const [loading2, setLoading2] = useState(false);

  const merchantsBalance = useSelector(
    (state: RootState) => state.userInfo.merchantInfo.merchantsBalance
  );

  const querenShouKuan = (item) => {
    Dialog.confirm({
      title: "提示",
      message: "您确定要确认收款吗？",
      backdrop: {
        style: { zIndex: 10000 },
      },
      style: {
        zIndex: 10001,
      },
      onConfirm() {
        if (Taro.canIUse("requestMerchantTransfer")) {
          Taro.showLoading({
            title: "处理中...",
          });

          (wx as any).requestMerchantTransfer({
            mchId: "1626364920", // 商户号
            appId: Taro.getAccountInfoSync().miniProgram.appId, // 当前小程序appid
            package: item.packageInfo,
            success: (res) => {
              Taro.hideLoading();
              console.log("收款确认成功:", res);

              // 注意：这里的success只是表示调起成功，不代表实际转账成功
              Toast.open({ type: "success", message: "收款确认已提交" });

              // 实际转账结果需要通过后端回调确认
            },
            fail: (res) => {
              Taro.hideLoading();
              console.log("收款确认失败:", res);

              Toast.open({ type: "fail", message: res.errMsg });
            },
          });
        }
      },
    });
  };

  const getProfitList = (status?: any) => {
    setLoading(true);
    let url = "merchants/getMyWithdrawalRecordList";
    if (status != 5) {
      url = "merchantsCommission/getMerchantCommissionList";
    }
    requestPOST(url, {
      status: status === 5 ? "" : status || "",
      isPage: 0,
    })
      .then((res: any) => {
        const { vos } = res;
        setProfitList([...vos]);
      })
      .finally(() => {
        setLoading(false);
      });
  };

  const handleChange = (value) => {
    setProfitList([]);
    setValue(value);
    getProfitList(value);
  };

  const getStatusName = (status) => {
    if (status === 0) {
      return "审核中";
    } else if (status === 1) {
      return "已通过";
    } else if (status === 2) {
      return "已拒绝";
    } else if (status === 3) {
      return "已取消";
    }
  };

  const getOrderList = (status?: string) => {
    setLoading1(true);
    requestPOST("merchantsCommission/getCommissionOrderList", {
      params: { status: status === undefined ? value : status, isPage: 0 },
    })
      .then((res: any) => {
        const { vos } = res;
        setOrderList([...vos]);
      })
      .finally(() => {
        setLoading1(false);
      });
  };

  const handleChange1 = (value) => {
    setOrderList([]);
    setValue1(value);
    getOrderList(value);
  };

  const getGoodsList = (value = value2) => {
    let url = "merchantsCommission/getUserOrderAmountRankingList";
    if (value === 2) {
      url = "merchantsCommission/getProductOrderAmountRankingList";
    } else if (value === 3) {
      url = "merchantsCommission/getProductNumberOrderAmountRankingList";
    }
    setLoading2(true);
    requestPOST(url, { params: { isPage: 0 } })
      .then((res: any) => {
        console.log(res);
        setGoodsList([...res.vos]);
      })
      .finally(() => {
        setLoading2(false);
      });
  };

  const handleChange2 = (value) => {
    setGoodsList([]);
    setValue2(value);
    getGoodsList(value);
  };

  const clipboard = (data) => {
    Taro.setClipboardData({
      data,
      success() {
        // Toast.open({ type: "success", message: "复制成功" });
      },
    });
  };

  const [info, setInfo] = useState<any>({
    pageNumIndex: 1,
    total: 0,
    loading: true,
    hasMore: true,
    list: [],
  });
  const orderId = useRef("");
  const [open1, setOpen1] = useState(false);
  const [open, setOpen] = useState(false);
  const [orderNo, setOrderNo] = useState("");

  const handleChangeValue = (item) => {
    if (info.loading) {
      abortRequest();
    }

    setValue3(item);
    setInfo({
      pageNumIndex: 1,
      total: 0,
      loading: true,
      hasMore: true,
      list: [],
    });
    getPromotionListByParam();
  };
  const getPromotionListByParam = useSyncCallback(() => {
    requestPOST("merchantsOrder/getMerchantOrderList", {
      isPage: 1,
      pageNumIndex: info.pageNumIndex,
      pageSizeIndex: 10,
      searchName: "",
      status: value3,
    }).then((res: any) => {
      const { total, vos } = res;
      const list = [...info.list, ...vos];
      if (list.length >= total) {
        setInfo({
          ...info,
          total: total,
          list: [...list],
          hasMore: false,
          loading: false,
        });
      } else {
        setInfo({
          ...info,
          total: total,
          list: [...list],
          hasMore: true,
          loading: false,
        });
      }
    });
  });

  const onLoad = () => {
    setInfo({ ...info, loading: true, pageNumIndex: info.pageNumIndex + 1 });
    getPromotionListByParam();
  };

  const cancelOrder = (id) => {
    Dialog.confirm({
      title: "提示",
      message: "您确定要取消订单吗？",
      backdrop: {
        style: { zIndex: 10000 },
      },
      style: {
        zIndex: 10001,
      },
      onConfirm() {
        requestPOST(`customerOrder/cancelOrder/${id}`).then(() => {
          Toast.open({ type: "success", message: "取消成功" });
          handleSearch();
        });
      },
    });
  };

  const refund = (id) => {
    Dialog.confirm({
      title: "提示",
      message: "您确定要退款吗？",
      backdrop: {
        style: { zIndex: 10000 },
      },
      style: {
        zIndex: 10001,
      },
      onConfirm() {
        orderId.current = id;
        setOpen(true);
      },
    });
  };

  const refundOrder = (id) => {
    Dialog.confirm({
      title: "提示",
      message: "您确定要提交退款申请吗？",
      backdrop: {
        style: { zIndex: 10000 },
      },
      style: {
        zIndex: 10001,
      },
      onConfirm() {
        requestPOST(`customerOrder/refundOrder/${id}`).then(() => {
          Toast.open({ type: "success", message: "提交成功" });
          handleSearch();
        });
      },
    });
  };

  const confirmOrderNo = () => {
    if (!orderNo)
      return Toast.open({ type: "fail", message: "请输入快递单号" });
    requestPOST(`customerOrder/refundUploadDeliveryNo`, {
      orderId: orderId.current,
      logisticsReturnNumber: "",
    }).then(() => {
      Toast.open({ type: "success", message: "退款成功" });
      setOpen(false);
      handleSearch();
    });
  };

  const toPay = ({ orderNo }) => {
    Dialog.confirm({
      title: "提示",
      message: "您确定要去支付吗？",
      backdrop: {
        style: { zIndex: 10000 },
      },
      style: {
        zIndex: 10001,
      },
      onConfirm() {
        requestPOST(`customerOrder/payOrder/${orderNo}`).then((res: any) => {
          const { nonceStr, paySign, prepayId, timeStamp } = res;
          if (nonceStr) {
            Taro.requestPayment({
              timeStamp: timeStamp,
              nonceStr: nonceStr,
              package: prepayId,
              signType: "MD5",
              paySign: paySign,
              success: (res) => {
                console.log(res);
                Toast.open({ type: "fail", message: "支付成功" });
                handleSearch();
              },
              fail: function (res) {
                console.log(res);
                Toast.open({ type: "fail", message: "支付失败" });
              },
            });
          }
        });
      },
    });
  };

  const buyOrder = (item) => {
    const { id } = item;
    Dialog.confirm({
      title: "提示",
      message: "您确定要再下一单吗？",
      backdrop: {
        style: { zIndex: 10000 },
      },
      style: {
        zIndex: 10001,
      },
      onConfirm() {
        requestPOST(`customerOrder/getUserOrderDetail/${id}`).then(
          (detail: any) => {
            requestPOST(`customerOrder/showAgainOrderInfo/${id}`).then(
              (params: any) => {
                let select = params.userCouponVos?.[0] || {};
                requestPOST("customerOrder/addAgainOrder", {
                  allTotalPrice: detail.orderTotalPrice,
                  couponsId: select?.id || "",
                  preferentialPrice: select?.couponPrice || 0,
                  payPrice: detail.orderPayPrice,
                  addCartOrderParams: [...params.cartPayInfoVos].map(
                    (item) => ({
                      ...item,
                      productTotalPrice: item.currentPrice * item.buyNum,
                      subTotalPrice:
                        item.currentPrice * item.buyNum + item.freightPrice,
                    })
                  ),
                  addCartOrderDeliveryParams: { ...params.cartDeliveryInfoVo },
                }).then((res: any) => {
                  const { nonceStr, paySign, prepayId, timeStamp } = res;
                  if (nonceStr) {
                    Taro.requestPayment({
                      timeStamp: timeStamp,
                      nonceStr: nonceStr,
                      package: prepayId,
                      signType: "MD5",
                      paySign: paySign,
                      success: (res) => {
                        console.log(res);
                        handleSearch();
                      },
                      fail: function (res) {
                        console.log(res);
                        Toast.open({ type: "fail", message: "支付失败" });
                        handleSearch();
                      },
                    });
                  }
                });
              }
            );
          }
        );
      },
    });
  };
  const handleSearch = () => {
    setInfo({
      pageNumIndex: 1,
      total: 0,
      loading: true,
      hasMore: true,
      list: [],
    });
    getPromotionListByParam();
  };

  const comfirmShop = (id) => {
    Dialog.confirm({
      title: "提示",
      message: "您确定要收货吗？",
      backdrop: {
        style: { zIndex: 10000 },
      },
      style: {
        zIndex: 10001,
      },
      onConfirm() {
        requestPOST(`customerOrder/confirmOrder/${id}`).then(() => {
          Toast.open({ type: "success", message: "收货成功" });
          handleSearch();
        });
      },
    });
  };

  const removeOrder = (id) => {
    Dialog.confirm({
      title: "提示",
      message: "您确定要删除订单吗？",
      backdrop: {
        style: { zIndex: 10000 },
      },
      style: {
        zIndex: 10001,
      },
      onConfirm() {
        requestPOST(`customerOrder/delOrder/${id}`).then(() => {
          Toast.open({ type: "success", message: "删除成功" });
          handleSearch();
        });
      },
    });
  };

  useEffect(() => {
    getProfitList();
    getOrderList();
    getGoodsList();
    getPromotionListByParam();
  }, []);

  return (
    <View className="taroContainer">
      <Navbar
        fixed
        nativeSafeTop
        safeArea="top"
        className="navBar"
        style={{ background: "#e3f3fe" }}
        placeholder={true}
      >
        <Navbar.Title style={{ maxWidth: "100%" }}>
          <View
            style={{
              display: "flex",
              alignItems: "center",
              width: "100vw",
              justifyContent: "center",
              position: "relative",
              fontSize: "28rpx",
              fontWeight: "normal",
            }}
          >
            <View style={{ position: "absolute", left: 20 }}>
              {merchantInfo.merchantName}
            </View>
            <View>订单收益</View>
          </View>
        </Navbar.Title>
      </Navbar>
      <View style={{ padding: "24rpx", position: "relative" }}>
        <Image src={BannerIcon} width="100%" height={210} />
        <View
          style={{
            color: "#fff",
            position: "absolute",
            top: "64rpx",
            left: "64rpx",
            right: "64rpx",
          }}
        >
          <View style={{ fontSize: "25rpx" }}>可提现金额（元）</View>
          <View
            style={{
              display: "flex",
              alignItems: "center",
              marginTop: "40rpx",
              justifyContent: "space-between",
            }}
          >
            <View style={{ display: "flex", alignItems: "baseline" }}>
              <View style={{ fontWeight: "bold", fontSize: "21rpx" }}>￥</View>
              <View style={{ fontWeight: "bold", fontSize: "33rpx" }}>
                {merchantsBalance}
              </View>
            </View>
            {merchantType == 1 && (
              <Button
                variant="outlined"
                shape="round"
                size="small"
                style={{ width: "140rpx", color: "#fff" }}
                onClick={() =>
                  Taro.navigateTo({ url: "/packages/withdrawal/index" })
                }
              >
                提现
              </Button>
            )}
          </View>
        </View>
      </View>
      <View>
        <View
          style={{
            padding: "24rpx",
            fontWeight: "bold",
            fontSize: "33rpx",
            color: "#333333",
          }}
        >
          收益管理
        </View>
        <Tabs
          value={value}
          onChange={(value) => handleChange(value)}
          ellipsis={false}
        >
          <Tabs.TabPane value={""} title="全部"></Tabs.TabPane>
          <Tabs.TabPane value={1} title="审核中"></Tabs.TabPane>
          <Tabs.TabPane value={2} title="已到账"></Tabs.TabPane>
          <Tabs.TabPane value={4} title="已退回"></Tabs.TabPane>
          <Tabs.TabPane value={5} title="提现记录"></Tabs.TabPane>
        </Tabs>
        <View style={{ padding: "24rpx" }}>
          <View
            style={{
              boxShadow: "0rpx 1rpx 9rpx 0rpx rgba(59,59,59,0.19)",
              borderRadius: "14rpx",
              background: "#fff",
            }}
          >
            <View
              style={{
                maxHeight: more ? "600rpx" : "400rpx",
                overflowY: "auto",
                transition: "0.3s height",
                padding: "14rpx",
              }}
            >
              {loading ? (
                <View style={{ textAlign: "center", marginTop: "40rpx" }}>
                  <Loading size={20}>加载中...</Loading>
                </View>
              ) : profitList.length ? (
                profitList.map((item) => (
                  <View
                    key={item.id}
                    style={{
                      display: "flex",
                      alignItems: "center",
                      gap: "20rpx",
                      padding: "26rpx 12rpx",
                      borderBottom: "1px solid #efefef",
                    }}
                  >
                    <Image
                      src={
                        value == 5
                          ? TixianIcon
                          : item.status == 1
                          ? ShenheIcon
                          : item.status == 2
                          ? DjiesuanIcon
                          : YjiesuanIcon
                      }
                      width={55}
                      height={55}
                    />
                    <View>
                      <View style={{ fontSize: "25rpx", color: "#333" }}>
                        {getStatusName(item.status)}
                      </View>
                      <View style={{ fontSize: "22rpx", color: "#999" }}>
                        {item.createTime}
                      </View>
                    </View>
                    <View
                      style={{
                        fontSize: "25rpx",
                        color: "#333",
                        fontWeight: "bold",
                        marginLeft: "auto",
                      }}
                    >
                      ￥{item.withdrawalPrice}
                    </View>
                    <View>
                      <Button
                        onClick={() => querenShouKuan(item)}
                        color="primary"
                        size="small"
                      >
                        确认收款
                      </Button>
                    </View>
                  </View>
                ))
              ) : (
                <Empty>
                  <Empty.Image />
                  <Empty.Description>暂无数据</Empty.Description>
                </Empty>
              )}
            </View>
            <View
              style={{
                fontSize: "22rpx",
                color: "#00A2FF",
                textAlign: "center",
                padding: "30rpx 0 15rpx 0",
              }}
              onClick={() => setMore(!more)}
            >
              <ArrowDown
                style={{
                  transform: more ? "rotate(-180deg)" : "rotate(0deg)",
                  transition: "0.3s all",
                }}
              />
              下拉加载更多
            </View>
          </View>
        </View>

        <View
          style={{
            padding: "24rpx",
            fontWeight: "bold",
            fontSize: "33rpx",
            color: "#333333",
            display: "flex",
            alignItems: "center",
            gap: "10rpx",
          }}
        >
          我的订单
        </View>

        {/* {active == 0 && (
          <View>
            <Tabs
              value={value1}
              onChange={(value) => handleChange1(value)}
              ellipsis={false}
            >
              <Tabs.TabPane value={""} title="全部"></Tabs.TabPane>
              <Tabs.TabPane value={1} title="已下单"></Tabs.TabPane>
              <Tabs.TabPane value={2} title="已付款"></Tabs.TabPane>
              <Tabs.TabPane value={3} title="已签收"></Tabs.TabPane>
              <Tabs.TabPane value={4} title="已完成"></Tabs.TabPane>
            </Tabs>
            <View style={{ padding: "24rpx" }}>
              <View
                style={{
                  boxShadow: "0rpx 1rpx 9rpx 0rpx rgba(59,59,59,0.19)",
                  borderRadius: "14rpx",
                  background: "#fff",
                }}
              >
                <View
                  style={{
                    maxHeight: more1 ? "1200rpx" : "600rpx",
                    overflowY: "auto",
                    transition: "0.3s height",
                    padding: "14rpx",
                  }}
                >
                  {loading1 ? (
                    <View style={{ textAlign: "center", marginTop: "40rpx" }}>
                      <Loading size={20}>加载中...</Loading>
                    </View>
                  ) : orderList.length ? (
                    orderList.map((item) => (
                      <View
                        key={item.id}
                        style={{
                          padding: "26rpx 12rpx",
                          borderBottom: "1px solid #efefef",
                        }}
                      >
                        <View
                          style={{
                            display: "flex",
                            alignItems: "center",
                            gap: "16rpx",
                            width: "100%",
                          }}
                        >
                          <Image
                            src={NoIcon}
                            width={26}
                            height={26}
                            mode="aspectFill"
                            style={{ verticalAlign: "10rpx" }}
                          />
                          <View style={{ fontSize: "22rpx", color: "#666" }}>
                            {item.orderNo}
                          </View>
                          <Image
                            onClick={() => clipboard(item.orderNo)}
                            src={FuzhiIcon}
                            width={26}
                            height={26}
                            mode="aspectFill"
                            style={{ verticalAlign: "10rpx" }}
                          />
                          <View
                            style={{
                              fontSize: "22rpx",
                              color: "#F90000",
                              marginLeft: "auto",
                            }}
                          >
                            {item.statusDesc}
                          </View>
                        </View>
                        <View
                          style={{
                            display: "flex",
                            gap: "25rpx",
                            marginTop: "30rpx",
                          }}
                        >
                          <View style={{ flex: "0 0 125rpx" }}>
                            <Image
                              src={
                                baseURL + item.orderDetailVos[0].productImage
                              }
                              width={125}
                              height={125}
                              style={{ borderRadius: "14rpx" }}
                            />
                          </View>
                          <View
                            style={{ display: "flex", flexDirection: "column" }}
                          >
                            <View style={{ fontSize: "22rpx", color: "#333" }}>
                              {item.orderDetailVos[0].productName}
                            </View>
                            <View style={{ fontSize: "21rpx", color: "#999" }}>
                              x{item.orderDetailVos.length}
                            </View>
                            <View
                              style={{
                                color: "#F90000",
                                display: "flex",
                                alignItems: "baseline",
                                marginTop: "auto",
                              }}
                            >
                              <View
                                style={{
                                  fontWeight: "bold",
                                  fontSize: "21rpx",
                                }}
                              >
                                ￥
                              </View>
                              <View
                                style={{
                                  fontWeight: "bold",
                                  fontSize: "33rpx",
                                }}
                              >
                                {item.orderTotalPrice}
                              </View>
                            </View>
                          </View>
                        </View>
                      </View>
                    ))
                  ) : (
                    <Empty>
                      <Empty.Image />
                      <Empty.Description>暂无数据</Empty.Description>
                    </Empty>
                  )}
                </View>
                <View
                  style={{
                    fontSize: "22rpx",
                    color: "#00A2FF",
                    textAlign: "center",
                    padding: "30rpx 0 15rpx 0",
                  }}
                  onClick={() => setMore1(!more1)}
                >
                  <ArrowDown
                    style={{
                      transform: more1 ? "rotate(-180deg)" : "rotate(0deg)",
                      transition: "0.3s all",
                    }}
                  />
                  下拉加载更多
                </View>
              </View>
            </View>
          </View>
        )} */}

        {/* {active == 1 && ( */}
        <View>
          <Tabs value={value3} onChange={handleChangeValue} ellipsis={false}>
            <Tabs.TabPane value={""} title="全部"></Tabs.TabPane>
            <Tabs.TabPane value={0} title="待支付"></Tabs.TabPane>
            <Tabs.TabPane value={1} title="待发货"></Tabs.TabPane>
            <Tabs.TabPane value={2} title="待收货"></Tabs.TabPane>
            <Tabs.TabPane value={3} title="退货/售后"></Tabs.TabPane>
            <Tabs.TabPane value={4} title="已完成"></Tabs.TabPane>
          </Tabs>
          <View
            style={{
              padding: "24rpx",
            }}
          >
            <View
              style={{
                boxShadow: "0rpx 1rpx 9rpx 0rpx rgba(59,59,59,0.19)",
                borderRadius: "14rpx",
                background: "#fff",
                padding: "14rpx",
              }}
            >
              <List
                loading={info.loading}
                hasMore={info.hasMore}
                onLoad={onLoad}
                fixedHeight
                style={{
                  height: more1 ? "1200rpx" : "600rpx",
                }}
              >
                <View>
                  {info.list.map((item) => (
                    <View
                      key={item.id}
                      style={{
                        padding: "26rpx 12rpx",
                      }}
                    >
                      <View
                        style={{
                          display: "flex",
                          alignItems: "center",
                          gap: "16rpx",
                          width: "100%",
                        }}
                      >
                        <Image
                          src={NoIcon}
                          width={26}
                          height={26}
                          mode="aspectFill"
                          style={{ verticalAlign: "10rpx" }}
                        />
                        <View style={{ fontSize: "22rpx", color: "#666" }}>
                          {item.orderNo}
                        </View>
                        <Image
                          onClick={() => clipboard(item.orderNo)}
                          src={FuzhiIcon}
                          width={26}
                          height={26}
                          mode="aspectFill"
                          style={{ verticalAlign: "10rpx" }}
                        />
                        <View
                          style={{
                            fontSize: "22rpx",
                            color: "#F90000",
                            marginLeft: "auto",
                          }}
                        >
                          {item.statusDesc}
                        </View>
                      </View>
                      {item.orderDetailVos.map((item1) => (
                        <View
                          style={{
                            display: "flex",
                            gap: "25rpx",
                            marginTop: "30rpx",
                          }}
                          onClick={() =>
                            Taro.navigateTo({
                              url: `/packages/orderDetail/index?orderId=${item.id}`,
                            })
                          }
                        >
                          <View style={{ flex: "0 0 125rpx" }}>
                            <Image
                              src={baseURL + item1.productImage}
                              width={125}
                              height={125}
                              style={{ borderRadius: "14rpx" }}
                            />
                          </View>
                          <View
                            style={{
                              display: "flex",
                              flexDirection: "column",
                            }}
                          >
                            <View style={{ fontSize: "22rpx", color: "#333" }}>
                              {item1.productName}
                            </View>
                            <View style={{ fontSize: "21rpx", color: "#999" }}>
                              x{item1.productBuyNumber}
                            </View>
                            <View
                              style={{
                                color: "#F90000",
                                display: "flex",
                                alignItems: "baseline",
                                marginTop: "auto",
                              }}
                            >
                              <View
                                style={{
                                  fontWeight: "bold",
                                  fontSize: "21rpx",
                                }}
                              >
                                ￥
                              </View>
                              <View
                                style={{
                                  fontWeight: "bold",
                                  fontSize: "33rpx",
                                }}
                              >
                                {item1.productCurrentPrice}
                              </View>
                            </View>
                          </View>
                        </View>
                      ))}
                      {item.orderUserType == 1 && (
                        <View
                          style={{
                            display: "flex",
                            alignItems: "center",
                            gap: "20rpx",
                            marginTop: "23rpx",
                            paddingTop: "23rpx",
                            borderTop: "1px solid #ddd",
                            justifyContent: "flex-end",
                          }}
                        >
                          {item.orderPayStatus == 0 && (
                            <Button
                              size="small"
                              onClick={() => cancelOrder(item.id)}
                            >
                              取消订单
                            </Button>
                          )}
                          {item.orderPayStatus == 1 &&
                            item.logisticsState == 2 &&
                            item.orderRefundStatus == 3 && (
                              <Button
                                size="small"
                                onClick={() => refund(item.id)}
                              >
                                退款
                              </Button>
                            )}
                          {item.orderPayStatus == 1 &&
                            item.logisticsState == 2 &&
                            item.orderRefundStatus == null && (
                              <Button
                                size="small"
                                onClick={() => refundOrder(item.id)}
                              >
                                退款申请
                              </Button>
                            )}
                          {item.orderPayStatus == 0 && (
                            <Button
                              size="small"
                              style={{
                                background: "#F90000",
                                color: "#fff",
                                border: "none",
                              }}
                              onClick={() => toPay(item)}
                            >
                              去支付
                            </Button>
                          )}
                          {(item.logisticsState == 0 ||
                            item.logisticsState == 2) &&
                            item.orderPayStatus != 3 && (
                              <Button
                                size="small"
                                color="primary"
                                variant="outlined"
                                onClick={() => buyOrder(item)}
                              >
                                再下一单
                              </Button>
                            )}
                          {item.logisticsState == 2 &&
                            item.orderPayStatus == 1 && (
                              <Button
                                size="small"
                                style={{
                                  background: "#FF9000",
                                  color: "#fff",
                                  border: "none",
                                }}
                                onClick={() => comfirmShop(item.id)}
                              >
                                确认收货
                              </Button>
                            )}
                          {((item.orderPayStatus != null &&
                            item.orderPayStatus == 2) ||
                            (item.logisticsState != null &&
                              item.logisticsState == 3)) && (
                            <Button
                              size="small"
                              onClick={() => removeOrder(item.id)}
                            >
                              删除订单
                            </Button>
                          )}
                          {/* {item.logisticsState === 3 && item.orderPayStatus === 1 && (
                    <Button
                      size="small"
                      color="primary"
                      onClick={() => {
                        setInfo22({
                          orderDetailId: item?.orderDetailVos
                            ?.map((item) => item.productId)
                            ?.join(","),
                          evaluationScore: 0,
                          evaluationContent: "",
                        });
                        setOpen1(true);
                      }}
                    >
                      立即评价
                    </Button>
                  )} */}
                        </View>
                      )}
                    </View>
                  ))}
                </View>
                <List.Placeholder>
                  {info.loading && <Loading>加载中...</Loading>}
                  {!info.hasMore && "没有更多了"}
                </List.Placeholder>
              </List>

              <View
                style={{
                  fontSize: "22rpx",
                  color: "#00A2FF",
                  textAlign: "center",
                  padding: "30rpx 0 15rpx 0",
                }}
                onClick={() => setMore1(!more1)}
              >
                <ArrowDown
                  style={{
                    transform: more1 ? "rotate(-180deg)" : "rotate(0deg)",
                    transition: "0.3s all",
                  }}
                />
                下拉加载更多
              </View>
            </View>
          </View>
        </View>
        {/* )} */}

        <View
          style={{
            padding: "24rpx",
            fontWeight: "bold",
            fontSize: "33rpx",
            color: "#333333",
          }}
        >
          销售排行
        </View>
        <Tabs
          value={value2}
          onChange={(value) => handleChange2(value)}
          ellipsis={false}
        >
          <Tabs.TabPane value={1} title="下单金额客户"></Tabs.TabPane>
          <Tabs.TabPane value={2} title="下单金额商品"></Tabs.TabPane>
          <Tabs.TabPane value={3} title="下单商品数量"></Tabs.TabPane>
        </Tabs>
        <View style={{ padding: "24rpx" }}>
          <View
            style={{
              boxShadow: "0rpx 1rpx 9rpx 0rpx rgba(59,59,59,0.19)",
              borderRadius: "14rpx",
              background: "#fff",
            }}
          >
            <View
              style={{
                maxHeight: more2 ? "600rpx" : "400rpx",
                overflowY: "auto",
                transition: "0.3s height",
                padding: "14rpx",
              }}
            >
              {loading2 ? (
                <View style={{ textAlign: "center", marginTop: "40rpx" }}>
                  <Loading size={20}>加载中...</Loading>
                </View>
              ) : goodsList.length ? (
                goodsList.map((item, index) => (
                  <View
                    key={item.id}
                    style={{
                      display: "flex",
                      alignItems: "center",
                      gap: "20rpx",
                      padding: "26rpx 12rpx",
                      borderBottom: "1px solid #efefef",
                    }}
                  >
                    {index <= 2 && (
                      <Image
                        src={
                          index == 0 ? A1Icon : index === 1 ? A2Icon : A3Icon
                        }
                        width={42}
                        height={54}
                        mode="aspectFill"
                      />
                    )}

                    <View style={{ fontSize: "25rpx", color: "#333" }}>
                      {item.productName}
                    </View>
                    <View
                      style={{
                        fontSize: "25rpx",
                        color: "#333",
                        fontWeight: "bold",
                        marginLeft: "auto",
                      }}
                    >
                      ￥{item.totalPrice}
                    </View>
                  </View>
                ))
              ) : (
                <Empty>
                  <Empty.Image />
                  <Empty.Description>暂无数据</Empty.Description>
                </Empty>
              )}
            </View>
            <View
              style={{
                fontSize: "22rpx",
                color: "#00A2FF",
                textAlign: "center",
                padding: "30rpx 0 15rpx 0",
              }}
              onClick={() => setMore2(!more2)}
            >
              <ArrowDown
                style={{
                  transform: more2 ? "rotate(-180deg)" : "rotate(0deg)",
                  transition: "0.3s all",
                }}
              />
              下拉加载更多
            </View>
          </View>
        </View>
      </View>

      <Dialog
        open={open}
        onClose={setOpen}
        backdrop={{ style: { zIndex: 10000 } }}
        style={{ zIndex: 10001 }}
      >
        <Dialog.Content>
          <Field label="快递单号">
            <Input
              placeholder="请输入快递单号"
              value={orderNo}
              onChange={(e) => setOrderNo(e.detail.value)}
            />
          </Field>
        </Dialog.Content>
        <Dialog.Actions>
          <Button
            onClick={() => {
              setOrderNo("");
              setOpen(false);
            }}
          >
            取消
          </Button>
          <Button onClick={confirmOrderNo}>确认</Button>
        </Dialog.Actions>
      </Dialog>
    </View>
  );
}
